package com.googlecode.yoohoo.xmppcore.protocol.parsing;

import com.googlecode.yoohoo.xmppcore.protocol.XmppProtocolException;
import com.googlecode.yoohoo.xmppcore.protocol.stanza.Iq;
import com.googlecode.yoohoo.xmppcore.protocol.stanza.error.BadRequest;

public class IqParserFactory extends AbstractXmppParserFactory<Iq> {
	private static final ProtocolKey PROTOCOL_KEY_IQ = new ProtocolKey("iq", null);

	@Override
	public IXmppParser<Iq> createParser() {
		return new IqParser();
	}
	
	private class IqParser extends StanzaParser<Iq> {

		@Override
		protected Iq createStanza() {
			return new Iq();
		}

		@Override
		public void processText(String path, String text) {
			if ((path.indexOf('/') == -1) && (text == null || "".equals(text))) {
				throw new XmppProtocolException(new BadRequest("Text isn't allowed in iq element."));
			}
		}
		
	}

	@Override
	public ProtocolKey getProtocolKey() {
		return PROTOCOL_KEY_IQ;
	}
	
}
